﻿#region Using

using System;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Data.OracleClient;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using NetBay.Core.DataAccess;
using NetBay.Core.Extensions;
using NetBay.Core.Log;
using Rio.Framework.RioManager;
using NetBay.Core.BusinessEntities.Versioning;
using NetBay.Core.BusinessEntities.Barcodes;

#endregion

namespace Rio.Doc.DataAccess
{
    public class DA_CAB
    {
        #region Enum

        /// <summary>
        /// List of DB functions to access data
        /// </summary>
        private enum DbFunction
        {
            [DescriptionAttribute("")]
            None,
            [DescriptionAttribute("P_CAB_Get")]
            GetBarcodes,
            [DescriptionAttribute("P_CAB_ALL_Get")]
            GetAllBarcodes,
            [DescriptionAttribute("P_CAB_Get_ById")]
            GetBarcodeById,
            [DescriptionAttribute("P_CAB_DOC_Get_ById")]
            GetBarcodeDocSepById,
            [DescriptionAttribute("P_CAB_FOLDER_Get_ById")]
            GetBarcodeFldSepById,
            [DescriptionAttribute("P_CAB_Add")]
            AddBarcode,
            [DescriptionAttribute("P_CAB_DOC_Add")]
            AddDocumentBarcodeSeparator,
            [DescriptionAttribute("P_CAB_FOLDER_Add")]
            AddFolderBarcodeSeparator,
            [DescriptionAttribute("P_CAB_Del")]
            DeleteBarcode,
            [DescriptionAttribute("P_CAB_DOC_Del")]
            DeleteDocumentBarcodeSeparator,
            [DescriptionAttribute("P_CAB_FOLDER_Del")]
            DeleteFolderBarcodeSeparator,
            [DescriptionAttribute("P_CAB_Get_ByCabParamCode")]
            GetBarcodeByParamCode,
            [DescriptionAttribute("P_CAB_All_Update")]
            UpdateBarcode,
            [DescriptionAttribute("P_CAB_Update")]
            UpdateBarcodeStatus,
            [DescriptionAttribute("P_INDEX_Unicity_Get")]
            CheckValueUniqueIndex,
        }

        #endregion Enum

        #region Add

        /// <summary>
        /// Adds the Barcode.
        /// </summary>
        /// <param name="Barcode">The Barcode.</param>
        /// <returns></returns>
        public static long AddBarcode(Barcode barcode)
        {
            //Variable initialization.
            var db = DbHelper.DataBase;
            long result = 0;

            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("DA_CAB.AddBarcode (barcode <" + barcode.ToString() + ">)...");

            try
            {
                using (var dbCommand = db.GetNewCommand(DbFunction.AddBarcode.szGetDescription()))
                {
                    db.AddInParameter(dbCommand, "p_sPrefix", DbType.String, barcode.Prefix);
                    db.AddInParameter(dbCommand, "p_sParam_code", DbType.String, barcode.ParamCode);
                    db.AddInParameter(dbCommand, "p_sName", DbType.String, barcode.Name);
                    db.AddInParameter(dbCommand, "p_sDescription", DbType.String, barcode.Description);
                    db.AddInParameter(dbCommand, "p_iFunction", DbType.Int32, Convert.ToInt32(barcode.Function));
                    db.AddInParameter(dbCommand, "p_lEnabled", DbType.Int32, Convert.ToInt32(barcode.Enabled));
                    db.AddInParameter(dbCommand, "p_lType", DbType.Int32, Convert.ToInt32(barcode.Type));

                    using (IDataReader reader = db.ExecuteReader(dbCommand))
                    {
                        while (reader.Read())
                        {
                            result = Convert.ToInt64(reader["r_cab_id"].ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Error.
                NetBay.Core.Log.LogManager.Instance().LogError("DA_CAB.AddBarcode Exception [" + ex.Message + "]");
            }
            
            return result;
        }

        /// <summary>
        /// Adds the barcode document separator.
        /// </summary>
        /// <param name="barcodeSeparator">The barcode separator.</param>
        /// <returns></returns>
        public static long AddBarcodeDocumentSeparator(BarcodeDocumentSeparator barcodeSeparator)
        {
            //variable initialization.
            var db = DbHelper.DataBase;
            long result = 0;

            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("DA_CAB.AddBarcodeDocumentSeparator (barcodeSeparator <" + barcodeSeparator.ToString() + ">)...");

            try
            {
                using (var dbCommand = db.GetNewCommand(DbFunction.AddDocumentBarcodeSeparator.szGetDescription()))
                {
                    db.AddInParameter(dbCommand, "p_lCab_id", DbType.Int64, barcodeSeparator.CabIdentifier);
                    db.AddInParameter(dbCommand, "p_sParamCode", DbType.String, barcodeSeparator.ParamCode);
                    db.AddInParameter(dbCommand, "p_lOrganization_id", DbType.Int64, barcodeSeparator.OrganizationId);
                    db.AddInParameter(dbCommand, "p_lFolder_type_id", DbType.Int64, barcodeSeparator.FolderTypeId);
                    db.AddInParameter(dbCommand, "p_sNature_name", DbType.String, barcodeSeparator.NatureName);
                    if (barcodeSeparator.ItemIdentifier == 0)
                    {
                        db.AddInParameter(dbCommand, "p_iItem_id", DbType.Int64, null);
                    }
                    else
                    {
                        db.AddInParameter(dbCommand, "p_iItem_id", DbType.Int64, Convert.ToInt64(barcodeSeparator.ItemIdentifier));
                    }
                    db.AddInParameter(dbCommand, "p_iPdf_merge", DbType.Int32, Convert.ToInt32(barcodeSeparator.PdfMerge));
                    db.AddInParameter(dbCommand, "p_iDelete_cab_page", DbType.Int32, Convert.ToInt32(barcodeSeparator.DeleteBarCodePage));
                    db.AddInParameter(dbCommand, "p_iManagment_error", DbType.Int32, Convert.ToInt32(barcodeSeparator.ErrorManagment));
                    db.AddInParameter(dbCommand, "p_iDoc_limit", DbType.Int32, Convert.ToInt32(barcodeSeparator.DocLimit));
                    db.AddInParameter(dbCommand, "p_iInferior_limit", DbType.Int32, Convert.ToInt32(barcodeSeparator.InfLimit));
                    db.AddInParameter(dbCommand, "p_iSuperior_limit", DbType.Int32, Convert.ToInt32(barcodeSeparator.SupLimit));

                    using (IDataReader reader = db.ExecuteReader(dbCommand))
                    {
                        while (reader.Read())
                        {
                            result = Convert.ToInt64(reader["r_cab_doc_id"].ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Error.
                NetBay.Core.Log.LogManager.Instance().LogError("DA_CAB.AddBarcodeDocumentSeparator Exception [" + ex.Message + "]");              
            }

            return result;
        }

        /// <summary>
        /// Adds the barcode folder separator.
        /// </summary>
        /// <param name="barcodeSeparator">The barcode separator.</param>
        /// <returns></returns>
        public static long AddBarcodeFolderSeparator(BarcodeFolderSeparator barcodeSeparator)
        {
            //variable initialization.
            var db = DbHelper.DataBase;
            long result = 0;

            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("DA_CAB.AddBarcodeFolderSeparator (barcodeSeparator <" + barcodeSeparator.ToString() + ">)...");

            try
            {
                using (var dbCommand = db.GetNewCommand(DbFunction.AddFolderBarcodeSeparator.szGetDescription()))
                {
                    db.AddInParameter(dbCommand, "p_lCab_id", DbType.Int64, barcodeSeparator.CabIdentifier);
                    db.AddInParameter(dbCommand, "p_iDelete_cab_page", DbType.Int32, Convert.ToInt32(barcodeSeparator.DeleteBarCodePage));
                    db.AddInParameter(dbCommand, "p_iManagment_error", DbType.Int32, Convert.ToInt32(barcodeSeparator.ErrorManagment));
                    db.AddInParameter(dbCommand, "p_iCorresp", DbType.Int32, Convert.ToInt32(barcodeSeparator.CorrespondenceFolder));
                    if (barcodeSeparator.CorrespondenceFolder)
                    {
                        db.AddInParameter(dbCommand, "p_lOrganization_id", DbType.Int64, barcodeSeparator.OrganizationId);
                        db.AddInParameter(dbCommand, "p_lFolder_type_id", DbType.Int64, barcodeSeparator.FolderTypeId);
                        db.AddInParameter(dbCommand, "p_iUnique_index_id", DbType.Int64, barcodeSeparator.UniqueIndexIdentifier);
                    }
                    else
                    {
                        db.AddInParameter(dbCommand, "p_lOrganization_id", DbType.Int64, null);
                        db.AddInParameter(dbCommand, "p_lFolder_type_id", DbType.Int64, null);
                        db.AddInParameter(dbCommand, "p_iUnique_index_id", DbType.Int64, null);
                    }
                    db.AddInParameter(dbCommand, "p_iStart_char", DbType.Int32, barcodeSeparator.StartChar);
                    db.AddInParameter(dbCommand, "p_iEnd_char", DbType.Int32, barcodeSeparator.EndChar);
                    db.AddInParameter(dbCommand, "p_iDoc_limit", DbType.Int32, Convert.ToInt32(barcodeSeparator.DocLimit));
                    db.AddInParameter(dbCommand, "p_iInferior_limit", DbType.Int32, barcodeSeparator.InfLimit);
                    db.AddInParameter(dbCommand, "p_iSuperior_limit", DbType.Int32, barcodeSeparator.SupLimit);
                    db.AddInParameter(dbCommand, "p_ifolder_page_limit", DbType.Int32, barcodeSeparator.PageLimit);
                    db.AddInParameter(dbCommand, "p_ifolder_document_limit", DbType.Int32, barcodeSeparator.DocumentLimit);

                    using (IDataReader reader = db.ExecuteReader(dbCommand))
                    {
                        while (reader.Read())
                        {
                            result = Convert.ToInt64(reader["r_cab_folder_id"].ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Error.
                NetBay.Core.Log.LogManager.Instance().LogError("DA_CAB.AddBarcodeFolderSeparator Exception [" + ex.Message + "]");   
            }

            return result;
        }

        #endregion Add

        #region Delete

        /// <summary>
        /// Deletes the barcode.
        /// </summary>
        /// <param name="barcodeId">The barcode id.</param>
        /// <returns></returns>
        public static bool DeleteBarcode(long barcodeId)
        {
            //Variable initialization.
            var db = DbHelper.DataBase;
            bool result = false;

            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("DA_CAB.DeleteBarcode (barcodeId <" + barcodeId.ToString() + ">)...");

            try
            {
                using (var dbCommand = db.GetNewCommand(DbFunction.DeleteBarcode.szGetDescription(), false))
                {
                    db.AddInParameter(dbCommand, "p_lCabId", DbType.Int64, barcodeId);
                    db.ExecuteNonQuery(dbCommand);
                }
                result = true;
            }
            catch (Exception ex)
            {
                //Error.
                NetBay.Core.Log.LogManager.Instance().LogError("DA_CAB.DeleteBarcode Exception [" + ex.Message + "]"); 
            }

            return result;
        }

        /// <summary>
        /// Deletes the barcode List.
        /// </summary>
        /// <param name="barcodeId">The barcode id List.</param>
        /// <returns></returns>
        public static bool DeleteBarcodeList(string p_sBarcodeIdList)
        {
            //Variable initialization.
            var db = DbHelper.DataBase;
            bool result = false;
            string[] l_aBarCodeId = p_sBarcodeIdList.Split(new[] { ';' });

            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("DA_CAB.DeleteBarcodeList (p_sBarcodeIdList <" + p_sBarcodeIdList + ">)...");

            try
            {
                foreach (string l_sBarCodeId in l_aBarCodeId)
                {
                    //Command declaration.
                    var dbCommand = db.GetNewCommand(DbFunction.DeleteBarcode.szGetDescription(), false);
                    db.AddInParameter(dbCommand, "p_lCabId", DbType.Int64, Convert.ToInt64(l_sBarCodeId));

                    //Execute Stored procedure.
                    db.ExecuteNonQuery(dbCommand);
                }
            }
            catch (Exception ex)
            {
                //Error.
                NetBay.Core.Log.LogManager.Instance().LogError("DA_CAB.DeleteBarcodeList Exception [" + ex.Message + "]"); 
            }

            return result;
        }

        /// <summary>
        /// Deletes the document barcode separator.
        /// </summary>
        /// <param name="Identifier">The identifier.</param>
        /// <returns></returns>
        public static bool DeleteDocumentBarcodeSeparator(long Identifier)
        {
            //Variable initialization.
            var db = DbHelper.DataBase;
            bool result = false;

            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("DA_CAB.DeleteDocumentBarcodeSeparator (Identifier <" + Identifier.ToString() + ">)...");

            try
            {

                using (var dbCommand = db.GetNewCommand(DbFunction.DeleteDocumentBarcodeSeparator.szGetDescription(), false))
                {
                    db.AddInParameter(dbCommand, "p_lCabDocId", DbType.Int64, Identifier);
                    db.ExecuteNonQuery(dbCommand);
                }
                result = true;
            }
            catch (Exception ex)
            {
                //Error.
                NetBay.Core.Log.LogManager.Instance().LogError("DA_CAB.DeleteDocumentBarcodeSeparator Exception [" + ex.Message + "]"); 
            }

            return result;
        }

        /// <summary>
        /// Deletes the folder barcode separator.
        /// </summary>
        /// <param name="Identifier">The identifier.</param>
        /// <returns></returns>
        public static bool DeleteFolderBarcodeSeparator(long Identifier)
        {
            //Variable initialization.
            var db = DbHelper.DataBase;
            bool result = false;

            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("DA_CAB.DeleteFolderBarcodeSeparator (Identifier <" + Identifier.ToString() + ">)...");

            try
            {

                using (var dbCommand = db.GetNewCommand(DbFunction.DeleteFolderBarcodeSeparator.szGetDescription(), false))
                {
                    db.AddInParameter(dbCommand, "p_lCabFldId", DbType.Int64, Identifier);
                    db.ExecuteNonQuery(dbCommand);
                }
                result = true;
            }
            catch (Exception ex)
            {
                //Error.
                NetBay.Core.Log.LogManager.Instance().LogError("DA_CAB.DeleteFolderBarcodeSeparator Exception [" + ex.Message + "]"); 
            }

            return result;
        }

        #endregion Delete

        #region Get

        /// <summary>
        /// Gets the barcodes.
        /// </summary>
        /// <returns></returns>
        public static IDataReader GetBarcodes(bool withEnabled = false)
        {
            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("DA_CAB.GetBarcodes (withEnabled <" + withEnabled.ToString() + ">)...");

            try
            {                
                //Variable initialization.
                var db = DbHelper.DataBase;
                var dbCommand = db.GetNewCommand(DbFunction.GetBarcodes.szGetDescription());
                db.AddInParameter(dbCommand, "p_iEnabled", DbType.Int32, Convert.ToInt32(withEnabled));

                return db.ExecuteReader(dbCommand);
            }
            catch (Exception ex)
            {
                //Error.
                NetBay.Core.Log.LogManager.Instance().LogError("DA_CAB.GetBarcodes Exception [" + ex.Message + "]");
                return null;
            }           
        }

        /// <summary>
        /// Gets the barcodes.
        /// </summary>
        /// <returns></returns>
        public static IDataReader GetAllTheBarCodes()
        {
            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("DA_CAB.GetAllTheBarCodes (No parameters)...");

            try
            {
                var db = DbHelper.DataBase;
                var dbCommand = db.GetNewCommand(DbFunction.GetAllBarcodes.szGetDescription());

                return db.ExecuteReader(dbCommand);
            }
            catch (Exception ex)
            {
                //Error.
                NetBay.Core.Log.LogManager.Instance().LogError("DA_CAB.GetAllTheBarCodes Exception [" + ex.Message + "]");
                return null;
            }           
        }

        /// <summary>
        /// Gets the barcode by id.
        /// </summary>
        /// <param name="barcodeId">The barcode id.</param>
        /// <returns></returns>
        public static IDataReader GetBarcodeById(long barcodeId)
        {
            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("DA_CAB.GetBarcodeById (barcodeId <" + barcodeId.ToString() + ">)...");

            try
            {
                var db = DbHelper.DataBase;

                var dbCommand = db.GetNewCommand(DbFunction.GetBarcodeById.szGetDescription());
                db.AddInParameter(dbCommand, "p_lCabId", DbType.Int64, barcodeId);

                return db.ExecuteReader(dbCommand);
            }
            catch (Exception ex)
            {
                //Error.
                NetBay.Core.Log.LogManager.Instance().LogError("DA_CAB.GetBarcodeById Exception [" + ex.Message + "]");
                return null;
            }
            
        }

        /// <summary>
        /// Gets the barcode by paramcode.
        /// </summary>
        /// <param name="p_sBarcodeParamcode">The param code barcode.</param>
        /// <returns></returns>
        public static IDataReader GetBarCodeId(string p_sBarcodeParamcode)
        {
            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("DA_CAB.GetBarCodeId (p_sBarcodeParamcode <" + p_sBarcodeParamcode + ">)...");

            try
            {
                var db = DbHelper.DataBase;

                var dbCommand = db.GetNewCommand(DbFunction.GetBarcodeByParamCode.szGetDescription());
                db.AddInParameter(dbCommand, "p_sParamCode", DbType.String, p_sBarcodeParamcode);

                return db.ExecuteReader(dbCommand);
            }
            catch (Exception ex)
            {
                //Error.
                NetBay.Core.Log.LogManager.Instance().LogError("DA_CAB.GetBarCodeId Exception [" + ex.Message + "]");
                return null;
            }
        }

        /// <summary>
        /// Gets the barcode document separtors by id.
        /// </summary>
        /// <param name="barcodeId">The barcode id.</param>
        /// <returns></returns>
        public static IDataReader GetBarcodeDocumentSepartorsById(long barcodeId)
        {
            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("DA_CAB.GetBarcodeDocumentSepartorsById (barcodeId <" + barcodeId.ToString() + ">)...");

            try
            {
                var db = DbHelper.DataBase;

                var dbCommand = db.GetNewCommand(DbFunction.GetBarcodeDocSepById.szGetDescription());
                db.AddInParameter(dbCommand, "p_lCabId", DbType.Int64, barcodeId);

                return db.ExecuteReader(dbCommand);
            }
            catch (Exception ex)
            {
                //Error.
                NetBay.Core.Log.LogManager.Instance().LogError("DA_CAB.GetBarcodeDocumentSepartorsById Exception [" + ex.Message + "]");
                return null;
            }
        }

        /// <summary>
        /// Gets the barcode folder separtors by id.
        /// </summary>
        /// <param name="barcodeId">The barcode id.</param>
        /// <returns></returns>
        public static IDataReader GetBarcodeFolderSepartorsById(long barcodeId)
        {
            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("DA_CAB.GetBarcodeFolderSepartorsById (barcodeId <" + barcodeId.ToString() + ">)...");

            try
            {
                var db = DbHelper.DataBase;

                var dbCommand = db.GetNewCommand(DbFunction.GetBarcodeFldSepById.szGetDescription());
                db.AddInParameter(dbCommand, "p_lCabId", DbType.Int64, barcodeId);

                return db.ExecuteReader(dbCommand);
            }
            catch (Exception ex)
            {
                //Error.
                NetBay.Core.Log.LogManager.Instance().LogError("DA_CAB.GetBarcodeFolderSepartorsById Exception [" + ex.Message + "]");
                return null;
            }
        }

        #endregion Get

        #region Update

        /// <summary>
        /// Update the Barcode.
        /// </summary>
        /// <param name="Barcode">The Barcode.</param>
        /// <returns></returns>
        public static long UpdateBarcode(Barcode barcode)
        {
            //Variable iitialization.
            var db = DbHelper.DataBase;
            long result = 0;

            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("DA_CAB.UpdateBarcode (barcode <" + barcode.ToString() + ">)...");

            try
            {
                using (var dbCommand = db.GetNewCommand(DbFunction.UpdateBarcode.szGetDescription()))
                {
                    db.AddInParameter(dbCommand, "p_lCab_id", DbType.Int64, barcode.Identifier);
                    db.AddInParameter(dbCommand, "p_sPrefix", DbType.String, barcode.Prefix);
                    db.AddInParameter(dbCommand, "p_sParam_code", DbType.String, barcode.ParamCode);
                    db.AddInParameter(dbCommand, "p_sName", DbType.String, barcode.Name);
                    db.AddInParameter(dbCommand, "p_sDescription", DbType.String, barcode.Description);
                    db.AddInParameter(dbCommand, "p_iFunction", DbType.Int32, Convert.ToInt32(barcode.Function));
                    db.AddInParameter(dbCommand, "p_lEnabled", DbType.Int32, Convert.ToInt32(barcode.Enabled));
                    db.AddInParameter(dbCommand, "p_lType", DbType.Int32, Convert.ToInt32(barcode.Type));

                    using (IDataReader reader = db.ExecuteReader(dbCommand))
                    {
                        while (reader.Read())
                        {
                            result = Convert.ToInt64(reader["r_cab_id"].ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Error.
                NetBay.Core.Log.LogManager.Instance().LogError("DA_CAB.UpdateBarcode Exception [" + ex.Message + "]");
            }
            
            return result;
        }

        /// <summary>
        /// Update the barcode status List.
        /// </summary>
        /// <param name="p_sBarcodeIdList">The barcode id List.</param>
        /// <param name="p_bBarCodeStatus">The Barcode status to update</param>
        /// <returns></returns>
        public static bool UpdateStatusBarcodeList(string p_sBarcodeIdList, Boolean p_bBarCodeStatus)
        {
            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("DA_CAB.UpdateStatusBarcodeList (p_sBarcodeIdList <" + p_sBarcodeIdList + ">), (p_bBarCodeStatus <" + p_bBarCodeStatus.ToString() + ">)...");

            //Variable declaration.
            var db = DbHelper.DataBase;
            bool result = false;
            string[] l_aBarCodeId = p_sBarcodeIdList.Split(new[] { ';' });

            //Status barcode value to update
            p_bBarCodeStatus = p_bBarCodeStatus ? false : true;

            try
            {
                foreach (string l_sBarCodeId in l_aBarCodeId)
                {
                    //Command declaration.
                    var dbCommand = db.GetNewCommand(DbFunction.UpdateBarcodeStatus.szGetDescription(), false);
                    db.AddInParameter(dbCommand, "p_lCabId", DbType.Int64, Convert.ToInt64(l_sBarCodeId));
                    db.AddInParameter(dbCommand, "p_iCabEnable", DbType.Int32, Convert.ToInt32(p_bBarCodeStatus));

                    //Execute Stored procedure.
                    db.ExecuteNonQuery(dbCommand);
                }
            }
            catch (Exception ex)
            {
                //Error.
                NetBay.Core.Log.LogManager.Instance().LogError("DA_CAB.UpdateStatusBarcodeList Exception [" + ex.Message + "]");
            }
           
            return result;
        }

        #endregion Update

        #region CheckUnicityIndex

        /// <summary>Check if the index value existe</summary>
        /// <returns></returns>
        public static IDataReader CheckUnicityIndexvalue(long p_lFolderTypeId, long p_lindexId, string p_sIndexValue, long p_lFolderId)
        {
            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("DA_CAB.CheckUnicityIndexvalue (p_lFolderTypeId <" + p_lFolderTypeId + ">), p_lindexId <" + p_lindexId + ">), p_sIndexValue <" + p_sIndexValue + ">), p_lFolderId <" + p_lFolderId + ">)...");

            try
            {
                var db = DbHelper.DataBase;

                var dbCommand = db.GetNewCommand(DbFunction.CheckValueUniqueIndex.szGetDescription());

                db.AddInParameter(dbCommand, "p_lFolderTypeId", DbType.Int64, p_lFolderTypeId);
                db.AddInParameter(dbCommand, "p_lIndexId", DbType.Int64, p_lindexId);
                db.AddInParameter(dbCommand, "p_sValue", DbType.String, p_sIndexValue);
                db.AddInParameter(dbCommand, "p_lFolderId", DbType.Int64, p_lFolderId);

                return db.ExecuteReader(dbCommand);
            }
            catch (Exception ex)
            {
                //Error.
                NetBay.Core.Log.LogManager.Instance().LogError("DA_CAB.CheckUnicityIndexvalue Exception [" + ex.Message + "]");
                return null;
            }
        }

        #endregion CheckUnicityIndex
    }
}
